/**
 * 
 */
package com.yam.michael.hibernate.dao.impl;

import java.io.Serializable;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xunjia.exception.XunjiaException;
import com.yam.michael.hibernate.dao.WalletDao;
import com.yam.michael.hibernate.pojo.Wallet;

/**
 * @author michael
 *
 */
public class WalletDaoImpl extends HibernateDaoSupport implements WalletDao,Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1095734200247928338L;
	// 日志
	private static final Logger logger = Logger.getLogger(WalletDaoImpl.class);
	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.WalletDao#addWallet(com.yam.michael.hibernate.pojo.Wallet)
	 * 添加一个钱包
	 */
	@Override
	public void addWallet(Wallet wallet) throws XunjiaException {
	 try {
		this.getHibernateTemplate().saveOrUpdate(wallet);
	} catch (DataAccessException e) {
		logger.info(e.getMessage());
		throw new XunjiaException("增加钱包发生错误,增加失败!!!");
	}
	}
	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.WalletDao#deleteWallet(com.yam.michael.hibernate.pojo.Wallet)
	 * 删除一个钱包
	 */
	@Override
	public void deleteWallet(Wallet wallet) throws XunjiaException {
		try {
			this.getHibernateTemplate().delete(wallet);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("删除钱包发生错误,删除失败!!!");
		}
	}

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.WalletDao#getWalletById()
	 * 通过id获得钱包信息
	 */
	@Override
	public Wallet getWalletById(final long walletID) throws XunjiaException {
		try {
			return (Wallet) this.getHibernateTemplate().load(Wallet.class, walletID);
		} catch (DataAccessException e) {
			logger.info(e.getMessage());
			throw new XunjiaException("通过ID获取钱包信息发生错误,获取失败!!!");
		}
	}

	/* (non-Javadoc)
	 * @see com.yam.michael.hibernate.dao.WalletDao#updateWallet(com.yam.michael.hibernate.pojo.Wallet)
	 * 更新钱包信息
	 */
	@Override
	public void updateWallet(Wallet wallet) throws XunjiaException {
	try {
		this.getHibernateTemplate().saveOrUpdate(wallet);
	} catch (DataAccessException e) {
		logger.info(e.getMessage());
		throw new XunjiaException("更新钱包信息发生错误,更新失败!!!");
	}
	}


}
